
*** compute SW F stats for multiple endogenous variables 


***Inputs: 
* $Data/normscore_IV60_ability.dta

***Outputs: 
* $Results/abilitybinary_SWF.tex




		
	use $Data/normscore_IV60_ability.dta, clear

		
	
	
xtile abovemedability = residmem,  nq(2)


	by anon_id, sort: egen mmm = min(abovemedability) if gamenum ==77
	
	replace abovemedability = mmm
	
	
	
	
	
	
	
foreach x in  1 2 {
	
	gen highpm_group`x' = highpm* (abovemedability  ==`x')
	
}




ivreghdfe highpm_group1 (highpm_group2  = c.maxzipwind#i.abovemedability ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group1 - pmgroup1hat 

reghdfe pmresid1 c.maxzipwind#i.abovemedability weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 1.abovemedability#c.maxzipwind 2.abovemedability#c.maxzipwind 

scalar FSW1 = r(F)*r(df)/(r(df)-1)
di FSW1


drop pmgroup1hat pmresid1 






ivreghdfe highpm_group2 (highpm_group1  = c.maxzipwind#i.abovemedability ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

predict pmgroup1hat 

gen pmresid1 = highpm_group2 - pmgroup1hat 


reghdfe pmresid1 c.maxzipwind#i.abovemedability weighted_wind_speed weighted_precipitation, absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

test 1.abovemedability#c.maxzipwind 2.abovemedability#c.maxzipwind 

scalar FSW2 = r(F)*r(df)/(r(df)-1)
di FSW2


drop pmgroup1hat pmresid1 




matrix Fstats = [FSW1 , FSW2]'


estout matrix(Fstats) using $Results/abilitybinary_SWF.tex, replace





